﻿using AutoMapper;
using GGGK.Film.IService;
using GGGK.Film.Models;
using GGGK.Film.Models.Models;
using Microsoft.AspNetCore.Mvc;

namespace GGGK.Film.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class RoomInfoController : ControllerBase
    {
        private readonly IRoomInfoService svc;
        private readonly IMapper mapper;

        public RoomInfoController(IRoomInfoService svc, IMapper mapper)
        {
            this.svc = svc;
            this.mapper = mapper;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="roomName"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        [HttpGet]
        public PagedResult<RoomInfo> Get(string roomName = "", int pageSize = 10, int pageIndex = 1)
        {
            var data = svc.Query(o => true);

            if (!string.IsNullOrEmpty(roomName)) data = data.Where(o => o.RoomName!.Contains(roomName));

            int total = data.Count();

            data = data.Skip(pageSize * (pageIndex - 1)).Take(pageSize);

            return new PagedResult<RoomInfo>() { code = 1, msg = "成功", data = data,total=total };
        }
    }
}
